package com.cq.hd.rabbit.consumer;

import com.cq.hd.common.constant.RabbitMqConstant;
import com.cq.hd.member.api.TbWithdrawalBillApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
@RabbitListener(queues = RabbitMqConstant.WITHDRAWAL_QUEUE)
public class WithdrawalMsgConsumer {

    @Autowired
    private TbWithdrawalBillApi withdrawalBillApi;

    @RabbitHandler
    public void receiveMsg(Map map) {
        log.info("接收到提现打款消息：" + map.toString());
        String messageId = (String) map.get("messageId");
        String withdrawalId = (String) map.get("messageData");
        log.info("withdrawalId:{}", withdrawalId);

        try {
            withdrawalBillApi.consumerWithdrawalMsg(Long.parseLong(withdrawalId));
        } catch (Exception e) {
            log.error("消费提现打款消息失败，withdrawalId：{}", withdrawalId, e);
        }
    }

}
